package pl.diagnoser.server;

import java.util.List;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import pl.diagnoser.server.persistance.dao.ObjectsDao;
import pl.diagnoser.server.persistance.dao.SymptomDao;
import pl.diagnoser.server.persistance.map.Estimate;
import pl.diagnoser.server.persistance.map.Objects;
import pl.diagnoser.server.persistance.map.Symptom;
import pl.diagnoser.server.persistance.tools.HibernateUtil;

public class MainTest {
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Objects objects = new ObjectsDao().getObject(64);
        List<Estimate> estimate = (List<Estimate>) session.createCriteria(Estimate.class).add(Restrictions.eq("estimateObject", objects)).list();
        session.getTransaction().commit();
		session.close();
		
		for(Estimate estView : estimate) {
        	List<Symptom> symptoms = new SymptomDao().getSymptomsForEstimate(estView);
        	if(symptoms != null) {
        		String tmpSymptoms = "";
        		int i = 0;
        		for(Symptom symptom : symptoms) {
        			i++;
        			if(i<symptoms.size())
        				tmpSymptoms += symptom.getSymptomName() + ",";
        			else
        				tmpSymptoms += symptom.getSymptomName();
        		}
        		System.out.println(estView.getEstDate() + " : " + estView.getDefect() + " : " + tmpSymptoms);
        	}
        }
	}
}